package com.luo.controller;

import com.alibaba.fastjson.JSON;
import com.luo.model.Result;
import com.luo.model.ResultObj;
import com.luo.model.User;
import com.luo.service.UserService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.xml.ws.Service;
import java.io.IOException;

/**
 * 功能：
 * 作者：Luo。
 * 日期：2024/1/29 16:35
 */
@WebServlet("/updateAdmin")
public class updateAdminController extends HttpServlet {

    UserService userService = new UserService();

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String id = req.getParameter("id");
        String username = req.getParameter("username");
        String sex = req.getParameter("sex");
        String age = req.getParameter("age");
        String img = req.getParameter("img");
        String phone = req.getParameter("phone");
        User user = new User();
        user.setId(Integer.valueOf(id));
        user.setUsername(username);
        user.setSex(sex);
        user.setAge(age);
        user.setImg(img);
        user.setPhone(phone);
        int i = userService.updateAdmin(user);
        ResultObj result = new ResultObj();
        result.setCode("" + i);
        if (i > 0) {
            result.setMsg("修改成功");
        } else {
            result.setMsg("修改失败");
        }
        String jsonString = JSON.toJSONString(result);
        resp.getWriter().write(jsonString);
        resp.getWriter().close();
    }
}
